<template>
  <div
    class="case-page"
    :id="uuid"
    style="
      font-family: Arial, sans-serif;
      padding: 34px 30px;
      background-color: #fff;
      height: 100%;
    "
  >
    <div
      style="
        padding: 30px 15px;
        background-color: #fff;
        height: 100%;
        width: 100%;
        margin: 0 auto;
        font-size: 12px;
        box-sizing: border-box;
      "
    >
      <!-- 医院名称 -->
      <h1
        class="hospital-name"
        style="
          margin-bottom: 5px;
          text-align: center;
          font-size: 16px;
          margin-bottom: 20px;
        "
      >
        {{ info.title }}
      </h1>
      <h1
        class="hospital-name"
        style="text-align: center; font-size: 16px; margin-bottom: 20px"
      >
        {{ info.rxName }}
      </h1>

      <!-- 患者基础信息 -->
      <div
        class="patient-info"
        style="
          display: flex;
          flex-wrap: wrap;
          border-bottom: 2px solid rgba(0, 0, 0, 0.9);
          margin-bottom: 10px;
          padding-bottom: 10px;
        "
      >
        <div
          class="info-item"
          style="
            width: 33.33%;
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          "
        >
          <span
            style="
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >姓名：</span
          >
          {{ info.patientName }}
          {{
            info.patientGender == 1
              ? '男'
              : info.patientGender == 2
              ? '女'
              : '未知'
          }}
        </div>
        <div
          class="info-item"
          style="
            width: 33.33%;
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          "
        >
          <span
            style="
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >年龄：</span
          >
          {{ info.ageYear }}年{{ info.ageMonth }}月
        </div>
        <div
          class="info-item"
          style="
            width: 33.33%;
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          "
        >
          <span
            style="
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >电话：</span
          >{{ info.phone }}
        </div>
        <div
          class="info-item"
          style="
            width: 33.33%;
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          "
        >
          <span
            style="
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >科室：</span
          >{{ info.deptName }}
        </div>
        <div
          class="info-item"
          style="
            width: 33.33%;
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          "
        >
          <span
            style="
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >诊号：</span
          >{{ info.visitNo }}
        </div>
        <div
          class="info-item"
          style="
            width: 33.33%;
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          "
        >
          <span
            style="
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >类型：</span
          >
          {{ info.visitType == 1 ? '初诊' : '复诊' }} ({{
            info.regType == 1 ? '普通' : '急诊'
          }})
        </div>
      </div>

      <div
        class="case-info"
        style="
          border-bottom: 2px solid rgba(0, 0, 0, 0.9);
          margin-bottom: 10px;
          padding-bottom: 10px;
        "
      >
        <div
          class="info-item"
          style="
            display: flex;
            width: 100%;
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
          "
        >
          <span
            style="
              width: 50px;
              display: block;
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >最终诊断</span
          >：
          <ul
            style="
              width: calc(100% - 100px);
              margin-left: 10px;
              list-style: none;
              padding: 0;
            "
          >
            <li>{{ info.diagnosis }}</li>
          </ul>
        </div>
      </div>

      <div
        class="case-info"
        style="
          border-bottom: 2px solid rgba(0, 0, 0, 0.9);
          margin-bottom: 10px;
          padding-bottom: 10px;
        "
      >
        <table
          style="
            font-size: 12px;
            text-align: left;
            border-collapse: separate;
            border-spacing: 10px 0;
          "
        >
          <tbody>
            <tr style="line-height: 2">
              <th>
                {{ info.tcmInfo.frequencyCodeText }}
              </th>
              <th style="padding: 0 10px">
                {{
                  useBaseDataStore.getEnumData(
                    info.tcmInfo.dailyDosage,
                    'tcmDailyDosageEnum'
                  )
                }}
              </th>
              <th style="padding: 0 10px">
                {{ info.tcmInfo.cycle }}{{ info.tcmInfo.cycleUnitText }}
              </th>
              <th style="padding: 0 10px">
                {{ info.tcmInfo.usageCodeText }}
              </th>
              <th style="padding: 0 10px">
                1次{{ info.tcmInfo.singleDosage }}ml
              </th>
              <th style="padding: 0 10px">{{ info.tcmInfo.remark }}</th>
            </tr>
          </tbody>
        </table>
        <div
          style="
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            align-items: flex-start;
          "
        >
          <div
            v-for="(item, index) in info.tcmInfo.detailList"
            :key="index"
            style="
              flex: 0 0 calc(33.33% - 10px);
              display: flex;
              padding: 8px;
              box-sizing: border-box;
              min-height: 66px;
              align-items: center;
            "
          >
            <div style="flex: 1; padding-right: 10px" v-if="!item.signature">
              {{ item.drugName }}
            </div>
            <div style="flex: 1; padding-right: 10px" v-else>
              <img
                :src="item.signature"
                alt=""
                style="height: 50px; width: 50px"
              />
            </div>

            <div
              style="
                display: flex;
                align-items: center;
                justify-content: flex-end;
              "
            >
              <span v-if="item.decotionMethod">
                [{{ item.decotionMethod }}]
              </span>
              <span style="margin-left: 10px; width: 80px"
                >{{ item.dosage }}{{ item.dosageUnitText }}</span
              >
            </div>
          </div>
        </div>
      </div>
      <div
        class="case-info"
        style="
          border-bottom: 2px solid rgba(0, 0, 0, 0.9);
          margin-bottom: 10px;
          padding-bottom: 10px;
        "
      >
        <div
          class="info-item"
          style="
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
            display: flex;
            width: 100%;
          "
        >
          <span
            style="
              width: 52px;
              display: block;
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >联系电话</span
          >：
          <div style="margin-left: 5px">{{ info.phone }}</div>
        </div>
        <div
          class="info-item"
          style="
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
            display: flex;
            width: 100%;
          "
        >
          <span
            style="
              width: 52px;
              display: block;
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >联系地址</span
          >：
          <div style="margin-left: 5px">{{ info.address }}</div>
        </div>
      </div>

      <!-- 底部信息 -->
      <div class="footer" style="display: flex; flex-wrap: wrap">
        <div
          class="info-item"
          style="
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
            display: flex;
            width: auto;
          "
        >
          <span
            style="
              width: 65px;
              display: block;
              text-align: justify;
              text-justify: inter-character;
              text-align-last: justify;
            "
            >打印时间：</span
          >
          <div style="margin-left: 5px">{{ info.printTime }}</div>
        </div>
      </div>
      <!-- 底部信息 -->
      <div class="footer2" style="width: 180px; margin-left: auto">
        <div
          class="info-item"
          style="
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
            display: flex;
            width: 100%;
            align-items: center;
            margin-bottom: 10px;
          "
        >
          <span style="display: block">医生姓名：</span>
          <div
            class="img"
            style="
              width: 120px;
              height: 40px;
              display: flex;
              justify-content: center;
            "
          >
            <div
              style="
                width: 120px;
                height: 40px;
                display: flex;
                justify-content: center;
              "
              v-if="info.signature"
            >
              <img :src="info.signature" alt="" style="height: 40px" />
            </div>
            <div v-else>{{ info.doctorName }}</div>
          </div>
        </div>
        <div
          class="info-item"
          style="
            font-size: 12px;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
            display: flex;
            width: 100%;
            align-items: center;
            margin-bottom: 10px;
          "
        >
          <span style="display: block">开单日期：</span>{{ info.diagnosisDate }}
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineComponent, reactive } from 'vue';
import stores from '@/store';
const useBaseDataStore = stores.useBaseDataStore();
const props = defineProps<{
  info: any;
  groupList: any[];
  uuid: string;
}>();
const getHtml = (uuid: string) => {
  // 获取dom9元素
  const dom9Element = document.getElementById(uuid);
  if (!dom9Element) {
    //console.error('未找到打印元素');
    //ElMessage.error('未找到打印内容');
    return;
  }
  const htmlContent = dom9Element.innerHTML || '';
  return htmlContent;
};
defineExpose<{
  getHtml: (value: any) => void;
}>({
  getHtml,
});
</script>

<!-- 删除:<style scoped lang="scss">
.case-page {
  font-family: Arial, sans-serif;
  padding: 34px 30px;
  background-color: #fff;
  height: 100%;
}

.hospital-name {
  text-align: center;
  font-size: 16px;
  margin-bottom: 20px;
}

.patient-info,
.footer {
  display: flex;
  flex-wrap: wrap;
}
.patient-info,
.case-info {
  border-bottom: 2px solid rgba(0, 0, 0, 0.9);
  margin-bottom: 10px;
  padding-bottom: 10px;
}
.info-item {
  font-size: 12px;
  width: 24%;
  font-weight: 400;
  font-size: 12px;
  color: #000000;
  line-height: 22px;
  text-align: left;
  font-style: normal;
  text-transform: none;
}
.footer {
  .info-item {
    display: flex;
    width: auto;
  }
}
.footer2 {
  width: 180px;
  margin-left: auto;
  .info-item {
    display: flex;
    width: 100%;
    align-items: center;
    span {
      display: block;
    }
    .img {
      width: 120px;
      height: 40px;
      display: flex;
      justify-content: center;
      img {
        height: 40px;
      }
    }

    margin-bottom: 10px;
  }
}
.case-info {
  .info-item {
    display: flex;
    width: 100%;
    span {
      width: 50px;
      display: block;
    }
  }
  .cdp-table {
    font-size: 12px;
    text-align: left;
    tr {
      td {
        vertical-align: middle;
      }
    }
  }
}
.info-item span {
  text-align: justify;
  text-justify: inter-character;
  text-align-last: justify;
}

ul {
  list-style: none;
  padding: 0;
}
</style> -->
